﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;

namespace Water.Util
{
    public class MultilistHashtable:IEnumerable,IEnumerator
    {
        private int position = -1;
        private int count;
        private List<DictionaryEntry> _value1 = new List<DictionaryEntry>();
        private List<DictionaryEntry> _value2 = new List<DictionaryEntry>();

        public virtual int Count
        {
            get { return count; }
        }

        public void Add(object key, object value1, object value2)
        {
            if(key==null)
               throw new ArgumentNullException("key", Water.Resources.Globalize.ExceptionResource.ExceptionMultilistHashtable);

            DictionaryEntry _v1 = new DictionaryEntry(key, value1);
            DictionaryEntry _v2 = new DictionaryEntry(key, value2);
            _value1.Add(_v1);
            _value2.Add(_v2);
            this.count++;
        }

        #region IEnumerable 成员

        public IEnumerator GetEnumerator()
        {
            return (IEnumerator)this;
        }

        #endregion

        #region IEnumerator 成员

        public object Current
        {
            get 
            {
                DictionaryEntry _temp1 = _value1[position];
                DictionaryEntry _temp2 = _value2[position];
                return new MultilistEntity(_temp1.Key, _temp1.Value, _temp2.Value);
            }
        }

        public bool MoveNext()
        {
            position++;
            return (position < _value1.Count);
        }

        public void Reset()
        {
            position = -1;
        }

        #endregion
    }
}
